﻿using SuperX.Common.Helper;
using SuperX.Helper.ServiceResponse;
using System.Text;

namespace SuperX.SuperSocket.Server
{
    public class Communication
    {
        private IOTSocketSession _session;
        public Communication(IOTSocketSession session)
        {
            _session = session;
        }
        public void Receiving(string ControllerName, string ActionName, object[] objects)
        {
            var ret = RpcProcessor.ExecutionAction(ControllerName, ActionName, objects);
            SendData(JsonHelper.TransferObjectJsonSerialize(ApiResponse<object>.Success(data: ret), false));
        }

        internal void SendData(string msg)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(msg);
            _session.Send(bytes, 0, bytes.Length);
        }
    }
}
